package jmine.tec.report.cell.impl;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Date;

import jmine.tec.report.cell.DataCell;

/**
 * DataCell that is a composite of other DataCells
 * 
 * @author gigante
 */
public class CompositeDataCell implements DataCell, Serializable {

    private static final long serialVersionUID = 1617576532221532627L;

    private final String format;

    private final DataCell[] cells;

    /**
     * C'tor
     * 
     * @param format the format to use
     * @param cells the cells that compose this {@link DataCell}
     */
    public CompositeDataCell(final String format, final DataCell... cells) {
        super();
        this.format = format;
        this.cells = cells;
    }

    /**
     * @see br.com.maps.fof.report.DataCell#toDate()
     * @return {@link Date}
     */
    public Date toDate() {
        return null;
    }

    /**
     * @see br.com.maps.fof.report.DataCell#toDouble()
     * @return {@link Double}
     */
    public Double toDouble() {
        return null;
    }

    /**
     * @see br.com.maps.fof.report.DataCell#toString(java.text.DateFormat, java.text.NumberFormat, java.text.NumberFormat)
     * @param dateFormat {@link DateFormat}
     * @param doubleFormat {@link NumberFormat}
     * @param currencyFormat {@link NumberFormat}
     * @return String
     */
    public String toString(final DateFormat dateFormat, final NumberFormat doubleFormat,
            final NumberFormat currencyFormat) {
        Object[] args = new Object[this.cells.length];
        for (int i = 0; i < args.length; i++) {
            args[i] = this.cells[i].toString(dateFormat, doubleFormat, currencyFormat);
        }
        return String.format(this.format, args);
    }

    /**
     * @see java.lang.Comparable#compareTo(java.lang.Object)
     * @param arg0 {@link DataCell} to compare to
     * @return boolen
     */
    public int compareTo(final DataCell arg0) {
        if (this.equals(arg0)) {
            return 0;
        }
        if (arg0 instanceof CompositeDataCell) {
            return this.format.compareTo(((CompositeDataCell) arg0).format);
        }
        return 1; // FIXME fix this after equals and hashcode
    }

    /**
     * @return the format
     */
    public String getFormat() {
        return this.format;
    }

    /**
     * @return the cells
     */
    public DataCell[] getCells() {
        return this.cells;
    }

}
